# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Maintainer: Carlo Landmeter <clandmeter@alpinelinux.org>
pkgname=gd
pkgver=2.3.3
pkgrel=8
_pkgreal=lib$pkgname
pkgdesc="Library for the dynamic creation of images by programmers"
url="https://libgd.github.io/"
arch="all"
license="custom"
makedepends="
	fontconfig-dev
	freetype-dev
	libavif-dev
	libjpeg-turbo-dev
	libpng-dev
	libwebp-dev
	libxpm-dev
	tiff-dev
	zlib-dev
	"
checkdepends="font-liberation"
subpackages="$pkgname-dev $pkgname-doc $_pkgreal:libs"
source="https://github.com/$_pkgreal/$_pkgreal/releases/download/gd-$pkgver/$_pkgreal-$pkgver.tar.xz"
builddir="$srcdir/$_pkgreal-$pkgver"

case "$CARCH" in
	# https://github.com/libgd/libgd/issues/359
	aarch64|mips*|ppc64le|riscv64|s390x|x86) options="!check";;
esac

# secfixes:
#   2.3.0-r1:
#     - CVE-2021-38115
#     - CVE-2021-40145
#   2.3.0-r0:
#     - CVE-2019-11038
#     - CVE-2018-14553
#     - CVE-2017-6363
#   2.2.5-r2:
#     - CVE-2018-5711
#     - CVE-2019-6977
#     - CVE-2019-6978
#   2.2.5-r1:
#     - CVE-2018-1000222

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info
	make
}

check() {
	TMPDIR=/tmp make check
}

package() {
	DESTDIR="$pkgdir" make install
	install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}

dev() {
	default_dev
	depends="$pkgname perl"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/bdftogd "$subpkgdir"/usr/bin/
}

sha512sums="
aa49d4381d604a4360d556419d603df2ffd689a6dcc10f8e5e1d158ddaa3ab89912f6077ca77da4e370055074007971cf6d356ec9bf26dcf39bcff3208bc7e6c  libgd-2.3.3.tar.xz
"
